package generic;

import java.lang.reflect.Array;

public class GenericArray <T>{

    private T[] array;

    public GenericArray(Class<T>cls , int capacity) {
        array = (T[]) Array.newInstance(cls,capacity);
    }

    public void put(int index, T element) {
        array[index] = element;
    }
    public T get(int index) {
        return array[index];
    }

    public T[] getArray() {
        return array;
    }

    public static void main(String[] args) {

        GenericArray<String> genericArray =new GenericArray(String.class ,3);
        genericArray.put(0,"spring");
        genericArray.put(1,"springAI");
        String value = genericArray.get(0);
        System.out.println(value);

        String[] array = genericArray.getArray();
        System.out.println(array);
    }
}
